from time import sleep
from random import randint, uniform

from src.consumer.mimo import MimoAdaptor
from src.logger import Logger
from src.processor.mimo_decode import DecodeBitStream


class MockedMatlabAdaptor(MimoAdaptor):
    def __init__(self, *args) -> None:
        Logger.Warn("matlab adaptor mocker enabled, should not be used in production")

    def mimo_decode(self, processor):
        """
        ## [ mock ] MIMO信道模型
        TODO: 会对参数进行校验, 但不会调用 matlab,
        若参数校验失败应直接抛出异常方便调试与测试
        """
        sleep(randint(5, 14))

        return DecodeBitStream(randint(0, 1) for _ in range(4))

    def mimo_plot(self, processor):
        """
        ## [ mock ] MIMO信道模型
        TODO: 会对参数进行校验, 但不会调用 matlab,
        若参数校验失败应直接抛出异常方便调试与测试
        """
        sleep(5 + processor.counts / 1000)

        x = list(range(-10, 21))
        y = [uniform(0, 1) for _ in range(31)]

        return (x, y)
